@extends('Home.User.Common.layout')
@section('title')
    知识分享_人事管理
@endsection
@section('content')
    <!--  content  -->
    <main class="common_content">
        <div class="container">
            <div class="ct_main">
                @include('Home.User.Hr.Common.hr_menu')
                <ul class="nav-items1 nav-items2 w999" id="tab-content2">
                    <!--知识分享-->
                    <li class="basic-sets active">
                        <form class="selector-head layui-form" method="post" action="{{route('hr_knowledge')}}">
                            @csrf
                            <h2>知识分享</h2>
                            <div class="rt">
                                <table class="date-picker">
                                    <thead>
                                    <tr>
                                        <th>
                                            <input type="text" placeholder="起始日期" class="span2" value="{{$between?$between[0]:''}}" name="date1" id="date1">
                                        </th>
                                        <th>
                                            <input type="text" placeholder="截止日期" class="span2" value="{{$between?$between[1]:''}}" name="date2" id="date2">
                                        </th>
                                    </tr>
                                    </thead>
                                </table>
                                <button class="layui-btn layui-btn-sm" lay-submit lay-filter="formSub"><i class="icon icon-search"></i></button>
                                @if (Auth::user()->hasAnyRole(['admin','leader']))
                                    <a href="javacsript:;" class="add-new-btn" title="添加知识分享" onclick="open_button('{{route('knowledge_add')}}','添加知识分享','1200')"><i class="icon icon-xinzen"></i></a>
                                @endif

                            </div>
                        </form>
                        <div class="layui-form basic-sets-ul">
                            <table class="layui-table">
                                <thead>
                                <tr>
                                    <th>编号</th>
                                    <th>文档标题</th>
                                    <th>文档类别</th>
                                    <th>更新日期</th>
                                    <th>建立人</th>
                                    <th>操作</th>
                                </tr>
                                </thead>
                                <tbody>
                                @foreach($list as $item)
                                    <tr>
                                        <td data-label="编号" title="{{$item->id}}"> {{$item->id}}</td>
                                        <td data-label="文档标题" title="{{$item->title}}">{{$item->title}}</td>
                                        <td data-label="文档类别" title="{{$item->category_name}}">{{$item->category_name}}</td>
                                        <td data-label="更新日期" title="{{$item->updated_at}}">{{$item->updated_at}}</td>
                                        <td data-label="建立人" title="{{$item->user_name}}">{{$item->user_name}}</td>
                                        <td data-label="操作" class="tac layui-row layui-col-space10">
                                            @if (Auth::user()->id==$item->assign)
                                                <a href="javascript:;" class="edit-btn edit-client" onclick="open_button('{{route('knowledge_edit',$item->id)}}','查看/编辑')" title="查看/编辑"><i class="layui-icon">&#xe642;</i></a>
                                                <a href="javascript:;" class="edit-btn add-schedule" onclick="del('{{route('del_knowledge',$item->id)}}')" title="删除"><i class="layui-icon">&#xe640;</i></a>
                                            @else
                                                <a href="javascript:;" class="edit-btn edit-client" onclick="open_button('{{route('knowledge_detail',$item->id)}}','查看/编辑')" title="查看/编辑"><i class="layui-icon">&#xe62a;</i></a>
                                            @endif
                                        </td>
                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                            <!-- 分页 s -->
                            @if($num>1)
                                <div class="news-pager">
                                    <ul class="pagination" id="page">
                                    </ul>
                                    <div class="pageJump">
                                        <span>跳转到</span>
                                        <input type="text"/>
                                        <span>页</span>
                                        <button type="button" class="button">确定</button>
                                    </div>
                                </div>
                            @endif
                            <!-- 分页 e -->
                        </div>
                    </li>
                </ul>
            </div>
        </div>
    </main>
@endsection
@section('footer')
    <script>
        layui.use(['laydate','form'], function(){
            var laydate = layui.laydate;
            var form = layui.form;

            //执行一个laydate实例
            laydate.render({
                elem: '#date1', //指定元素
            });

            //执行一个laydate实例
            laydate.render({
                elem: '#date2', //指定元素
            });

            //监听提交
            form.on('submit(formSub)', function(data){
                if (data.field.date1.length<=0){
                    layer.msg('起始日期必填',{icon:2});
                    return false;
                }else if (data.field.date2.length<=0){
                    layer.msg('截止日期必填',{icon:2});
                    return false;
                }
            });
        });
        /*删除*/
        function del(url) {
            layer.confirm("你确定要删除吗？此操作不能撤销！", {icon: 3, title:'提示'},
                    function(index){//确定回调
                        $.ajax({
                            type: 'get',
                            url: url,
                            dataType: 'json',
                            success: function(data){
                                if(data.code){
                                    window.location.reload();
                                    layer.close(index);
                                }else{
                                    layer.msg(data.msg,{icon: 5,time:1000});
                                }
                            },
                            error:function() {
                                layer.msg('服务器错误!',{icon: 5,time:1000});
                            }
                        });
                    },function (index) {//取消回调
                        layer.close(index);
                    }
            );
        }
        /***  分页 JS  ***/
        Page({
            num: '{{$num}}',		//页码数
            startnum: '{{$page}}',				//指定页码
            elem:$('#page'),		//指定的元素
            callback:function(n){	//回调函数
                @if($between)
                    window.location.href = '{{route('hr_knowledge')}}?page='+n+'&date1={{$between[0]}}&date2={{$between[1]}}';
                @else
                    window.location.href = '{{route('hr_knowledge')}}?page='+n;
                @endif
            }
        });
    </script>
@endsection